import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { CharacterGemInventoryEntity } from "./character-gem-inventory.entity";
import { GemBaseEntity } from "./gem-base.entity";

@Entity("equipment_gem_socket")
@ManualTimestamp()
export class EquipmentGemSocketEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "character_id", comment: "角色ID" })
  characterId!: number;

  @Column("int", { name: "equipment_id", comment: "装备ID" })
  equipmentId!: number;

  @Column("int", {
    name: "equipment_type",
    comment: "装备类型：1头盔 2武器 3铠甲 4项链 5护腕 6鞋子",
  })
  equipmentType!: number;

  @Column("int", { name: "socket_slot", comment: "宝石槽位：1,2,3" })
  socketSlot!: number;

  @Column("int", { name: "gem_inventory_id", comment: "宝石背包ID" })
  gemInventoryId!: number;

  @Column("int", { name: "gem_base_id", comment: "宝石基础ID" })
  gemBaseId!: number;

  @Column("varchar", { length: 100, name: "gem_name", comment: "宝石名称" })
  gemName!: string;

  @Column("int", { name: "gem_level", comment: "宝石等级" })
  gemLevel!: number;

  @Column("int", {
    name: "gem_attribute_type",
    nullable: true,
    comment: "宝石属性类型",
  })
  gemAttributeType!: number;

  @Column("int", {
    name: "gem_attribute_value",
    default: 0,
    comment: "宝石属性值",
  })
  gemAttributeValue!: number;

  @Column("datetime", {
    name: "socketed_at",
    comment: "镶嵌时间",
  })
  socketedAt!: Date;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(
    () => CharacterEntity,
    (character) => character.equipmentGemSockets
  )
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;

  @ManyToOne(() => CharacterGemInventoryEntity)
  @JoinColumn({ name: "gemInventoryId" })
  gemInventory!: CharacterGemInventoryEntity;

  @ManyToOne(() => GemBaseEntity)
  @JoinColumn({ name: "gemBaseId" })
  gemBase!: GemBaseEntity;
}
